﻿using Oxygen.Client.ServerProxyFactory.Interface;
using RpcInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServiceSample
{
    public class HelloServiceImpl : IHelloService
    {
        private readonly IEventBus _eventBus;
        private readonly IStateManager _stateManager;
        public HelloServiceImpl(IEventBus eventBus,
            IStateManager stateManager)
        {
            _eventBus = eventBus;
            _stateManager = stateManager;
        }

        public async Task<OutDto> HelloWorld()
        {
            var result = await _stateManager.GetState<OutDto>(new TestState());
            Console.WriteLine($"test state from clinentsample key={new TestState().Key}, data={result.Word}");
            return await Task.FromResult(new OutDto() { Word = "Hello Nobody" });
        }

        public async Task<OutDto> HelloWorldByEvent()
        {
            await _eventBus.SendEvent("HelloCallback", new HelloEventData()
            {
                Words = "Hello Event"
            });
            Console.WriteLine($"test event servicesample publish HelloCallback event.");
            return await Task.FromResult(new OutDto() { Word = "Hello Event" });
        }

        public async Task<OutDto> HelloWorldByName(InputDto input)
        {
            return await Task.FromResult(new OutDto() { Word = $"Hello {input.Name}" });
        }
    }
}
